//
//  CompereShowView.m
//  RainbowFM
//
//  Created by Kratos on 14/12/11.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "CompereShowView.h"

#import "RFMImageView.h"

@interface CompereShowView()<SwipeViewDataSource,SwipeViewDelegate>

@property (nonatomic , strong) NSMutableArray *showData;//商家信息

@end


@implementation CompereShowView

- (void)awakeFromNib {
    _showData = [NSMutableArray array];
}


-(void)updateCompereShowData:(NSArray *)showData
{
    [_showData removeAllObjects];
    [_showData addObjectsFromArray:showData];
    
    [_showScrollView reloadData];
}

#pragma mark -SwipeViewDataSource
- (NSInteger)numberOfItemsInSwipeView:(SwipeView *)swipeView
{
    return [_showData count];
}

- (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
    RFMImageView *showImageView = (RFMImageView *)view;
    if (!showImageView) {
        showImageView = [[RFMImageView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(_showScrollView.bounds)/2, CGRectGetHeight(_showScrollView.bounds))];
        
        view = showImageView;
    }
    
    RFMImageViewItem *item = _showData[index];
    
    [showImageView setItem:item];
    
    return view;
}

#pragma mark - SwipeViewDelegate
- (void)swipeViewCurrentItemIndexDidChange:(SwipeView *)swipeView
{
    if ([_delegate respondsToSelector:@selector(currentItemIndexDidChange:view:)]) {
        [_delegate currentItemIndexDidChange:swipeView.currentItemIndex view:self];
    }
}

- (void)swipeView:(SwipeView *)swipeView didSelectItemAtIndex:(NSInteger)index
{
    if ([_delegate respondsToSelector:@selector(didSelectItemAtIndex:view:)]) {
        [_delegate didSelectItemAtIndex:index view:self];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
